<template>
  <div class='subson' >
      <div class="name">{{name}}</div>
      <van-card
      v-for="data in list"
       :key="data.id"
  :price="data.min_price"
  :title="data.name"
  :thumb="data.picture"
  origin-price="10.00"
>
 <template #desc>
   <p :class="data.description===''?'hidden':'desc'">{{data.description }}</p>
   <p><span>月销{{data.month_saled}}</span><span>{{data.praise_content}}</span></p>
  </template>

   <template #num>
     <div class="num">
    <p class="add" @click="onChang(data.min_price,data)">选规格</p>
  </div>
  </template>
</van-card>
<van-submit-bar :price="totalMoney" button-text="去结算" @submit="onSubmit" currency="￥" >
</van-submit-bar>
<div class="nuum">共计： <span>{{totalAmount}}</span></div>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex'
export default {
  name: 'cart',
  data () {
    return {
      list: [],
    }
  },
  methods: {
    ...mapMutations(['addToCart']),
    onChang (price, data) {
      console.log(data, '加入成功', this.datalist)
      const { picture, name, id } = data
      const list = {
        id,
        price: Number(price),
        picture,
        name,
        num: 1,
        title: this.datalist.poi_info.name,
        image: this.datalist.poi_info.pic_url,

      }
      this.addToCart(list)
      this.$toast({
        message: '加入成功',
        duration: 500,
      })
    },
    onSubmit () {

    },
  },
  computed: {
    ...mapState({
      datalist: state => state.deatilslist.datalist,
    }),
    ...mapGetters(['totalMoney', 'totalAmount']),
  },
  watch: {
    // 当导航路径切换变化时，执行
    $route: {
      // 处理器
      handler (newVal) {
        console.log(newVal, '路由')
        // console.log('路径变化了:', newVal.query.id)
        // 获取路径中传递的查询字符串参数
        const { id } = newVal.params
        // 根据 id 查询该分类下的子分类数据
        this.name = this.datalist.food_spu_tags[id].name
        console.log(this.name)
        this.list = this.datalist.food_spu_tags[id].spus
        console.log(this.list, id + '条')
      },
      immediate: true, // 组件实例创建时，立刻调用 handler 处理器
    },
  },
}
</script>

<style lang='less' scoped>
.name{
    text-align: left;
    font-size: 15px;
    padding-left: 35px;
}
.van-card__title{
    font-size: 16px;
    color: #333333;
    font-weight: bold;
    margin-bottom: 2px;
}
.desc{
    width: 350px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
p{
    span{
color: red;
margin-right: 5px;
    }
}
.add,.van-cell__value{
        border-radius: 25px;
    background-color: #ffbd27;
    background-image: linear-gradient(
-135deg, #FFBD27 0%, #FFD161 100%);
    line-height: 35px;
    font-size: 12px;
    padding: 0 10px;
    color: black;
}
.van-sidebar-item--select::before{
 opacity: 0;
  content: "";
  width: 0px;
  height: 0;
}
.van-cell--clickable{
  background-color:#eeedea55;
}
.hidden{
  height: 40px;

}
.van-submit-bar{

  position: fixed;
  bottom: 0px;
  z-index: 9999;
}
.nuum{
  position: fixed;
  left: 0;
  bottom:25px;
   z-index: 10000;
   font-size: 14px;
}
</style>
